from appium import webdriver

import time

from selenium.webdriver.common.by import By

desired_caps = dict()
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1'
desired_caps['deviceName'] = '111'
desired_caps['appPackage'] = 'com.android.settings'
desired_caps['appActivity'] = '.Settings'

driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
# 通过id定位放大镜按钮，点击
search_button = driver.find_element(By.ID, 'com.android.settings:id/search')
search_button.click()
# 通过class定位输入框，输入hello
driver.find_element(By.CLASS_NAME, 'android.widget.EditText').send_keys('hello world')
# 通过xpath定位返回按钮，点击
driver.find_element(By.XPATH, "//*[@content-desc='收起']").click()

time.sleep(5)
driver.quit()
